/*
处理入库问题
1. 删除21号00:00以后的历史仓位数据、历史委托、成交记录
2. 重置用户的芝麻盈亏（取20号，即每个人的最后一次同步记录的总盈亏），
3. 同步用户的历史仓位，修改用户表的金额
*/
import { delLiShiPositionApi, resetUserYingKuiApi } from '@/api';
import { useRequest } from 'ahooks';
import { Button, Card, DatePicker, Input, Space } from 'antd';
import dayjs from 'dayjs';
import { useState } from 'react';
// export const delLiShiPositionApi = (params = {}) => get(`/hdapi/positions/delLiShiPosition`, params); // 删除指定时间段的历史仓位

export default function HandleRuKu() {
  const [time, setTime] = useState<string>('2025-04-14');
  const { loading, run: deleteData } = useRequest(
    async () => {
      const params = { startTime: '2025-04-14' };
      console.log('params:删除指定数据 ', params);
      const res = (await delLiShiPositionApi(params))?.data;
      console.log('res: 删除指定数据', res);
    },
    { manual: true },
  );

  // 重置用户总盈亏
  const { loading: resetLoading, run: resetYingkui } = useRequest(
    async () => {
      const startTime = dayjs(time).subtract(1, 'day').format('YYYY-MM-DD');
      const params = { startTime, endTime: startTime };
      console.log('params: 重置用户总盈亏', params);
      const res = (await resetUserYingKuiApi(params))?.data;
      console.log('res: 重置用户总盈亏', res);
    },
    { manual: true },
  );

  const dateFormat = 'YYYY-MM-DD';

  return (
    <Card>
      <Space>
        <DatePicker value={dayjs(time, dateFormat)} onChange={(e, str) => setTime(str)} />
        <Button loading={loading} onClick={deleteData}>
          删除指定数据
        </Button>
        <Button loading={resetLoading} onClick={resetYingkui}>
          重置用户总盈亏
        </Button>
      </Space>
    </Card>
  );
}
